package com.battle.service.controller.web;

import com.battle.pojo.param.carWarCase.GetCarWarCaseListParam;
import com.battle.pojo.param.trainingAchievement.GetTrainingAssessmentListByUserIdParam;
import com.battle.pojo.param.trainingAchievement.ImportTrainingAchievementParam;
import com.battle.pojo.param.trainingAchievement.ImportTrainingAssessmentParam;
import com.battle.pojo.param.trainingAssessment.*;
import com.battle.pojo.vo.trainingAssessment.*;
import com.battle.service.service.in.*;
import com.battle.service.utils.FileUtil;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * web/训练考核
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/trainingAssessment/web")
public class TrainingAssessmentWebController {

    private final TrainingAssessmentService service;

    public TrainingAssessmentWebController(TrainingAssessmentService service) {
        this.service = service;
    }


    /**
     * 获取训练考核详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getTrainingAssessment")
    public ApiResult<GetTrainingAssessmentVo> getTrainingAssessment(@RequestParam("id") Long id) {
        GetTrainingAssessmentVo vo = service.getTrainingAssessment(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取训练考核列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getTrainingAssessmentList")
    public ApiResult<PageResult<GetTrainingAssessmentListVo>> getTrainingAssessmentList(@RequestBody GetTrainingAssessmentListParam param) {
        PageResult<GetTrainingAssessmentListVo> result = service.getTrainingAssessmentList(param);
        return ApiResult.ok(result);
    }

    /**
     * 个人训练考核
     *
     * @param param
     * @return
     */
    @PostMapping("/getTrainingAssessmentListByUserId")
    public ApiResult<PageResult<GetTrainingAssessmentListVo>> getTrainingAssessmentListByUserId(@RequestBody GetTrainingAssessmentListByUserIdParam param) {
        PageResult<GetTrainingAssessmentListVo> result = service.getTrainingAssessmentListByUserId(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出个人训练记录
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportTrainingAssessmentListByUserId")
    public void exportTrainingAssessmentListByUserId(HttpServletResponse response, @RequestBody GetTrainingAssessmentListByUserIdParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }

    /**
     * 下载模板
     *
     * @param response
     */
    @PostMapping(value = "/downTemplate")
    public void downTemplate(HttpServletResponse response) {
        //模板名称
        String fileName = "trainingAssessment.xlsx";
        FileUtil.downloadFile(response, fileName);
    }


    /**
     * 导入培训考核
     * @param param
     */
    @PostMapping("/importTrainingAssessment")
    public ApiResult importTrainingAssessment(@RequestBody ImportTrainingAssessmentParam param) throws IOException {
        service.importTrainingAssessment(param);
        return ApiResult.ok();
    }


}

